<?php

class NotaController extends BaseController {

//Nota Type
	public function getNota()
	{
		Session::forget('filter');
		$notatype = DB::table('ref_bill')
				->join('ref_papertype','papertype_id','=','bill_papertype_id')
				->where('bill_isdelete','=',0)
				->paginate(10);
		return View::make('admin.nota.nota')->with('notatype',$notatype);
	}

	public function postNota()
	{
		$filter = Input::get('filter');
		Session::put('filter',Input::get('filter'));
		$notatype = DB::table('ref_bill')
		->join('ref_papertype','papertype_id','=','bill_papertype_id')
		->where('bill_isdelete','=',0)
		->where('bill_name','LIKE','%'.$filter.'%')
		->paginate(10);
		return View::make('admin.nota.nota')->with('notatype',$notatype);
	}

	public function postAddnota()
	{
		$addnota = refbill::create(Input::all());

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Add data nota";	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/nota')->with('message','Data jenis Nota berhasil ditambahkan');
	}

	public function postEditnota($id)
	{
		$editnota = refbill::find($id);
		$editnota->bill_name = Input::get('bill_name');
		$editnota->bill_qty_ply = Input::get('bill_qty_ply');
		$editnota->bill_qty_color = Input::get('bill_qty_color');
		$editnota->bill_papertype_id = Input::get('bill_papertype_id');
		$editnota->bill_size = Input::get('bill_size');
		$editnota->bill_price = Input::get('bill_price');
		$editnota->bill_qty_price = Input::get('bill_qty_price');
		$editnota->bill_qty_unit = Input::get('bill_qty_unit');
		$editnota->save();


		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Edit data nota ".$id;	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		return Redirect::to('/nota')->with('message','Data jenis Nota berhasil diubah');
	}

	public function postDeletenota()
	{
		$notas = DB::table('ref_bill')
				->get();
		foreach($notas as $notas){
		if(Input::get($notas->bill_id)=='1'){
			$nota = DB::table('ref_bill')
					->where('bill_id','=',$notas->bill_id)
					->update(array('bill_isdelete' => 1));

		$log = New adminlog();
		$log->admin_log_admin_id = Session::get('admin_id');	
		$log->admin_log_activity = "Delete data nota ".$notas->bill_id;	
		$log->admin_log_date = date('Y-m-d H:i:s');	
		$log->save();
		}
		}
		return Redirect::to('/nota')->with('message','Data jenis Nota berhasil dihapus');
	}


}